<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib uri="/struts-tags" prefix="s" %>
<%
String uuid = request.getParameter("uuid");
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/sys/menu/";  //应用的地址名
String treeName = request.getParameter("treeName");  //菜单树的名称
String viewAreaName = request.getParameter("viewAreaName");  //菜单查看区域的id名称
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    
    <title>菜单表编辑</title>
<script type="text/javascript">
<!--
           $(function(){
               //初始化工作，因为远程载入该界面时无法通过在标签中进行设置相应的验证属性等信息，必须要在这里进行初始化
               //$('#add').linkbutton();
               //$('#save').linkbutton();
               $('#vcName').validatebox({
                   required:'true',
                   missingMessage:'必须输入菜单名称',
                   validType:'length[1,25]&specialChar'
               });
	           $('#intSeq').validatebox({
	              required:'true',
	              missingMessage:'必须输入数字排序号',
	              validType:'intNumber[0,9999]'
	           });
               //url
               $('#vcUrl').validatebox({
                   validType:'length[1,150]&specialHtmlChar'
               });
               $('#vcParId').combotree({
				    url:'<%=path%>/sys/menu/SysMenu_searchMenuJsonTree.action',  //获取json格式的节点树
				    valueField:'id',
                    textField:'text',
                    required:true,              //要求必填
                    missingMessage:'请选择所属菜单'
			    });
               //菜单描述
               $('#vcMemo').validatebox({
                   validType:'length[1,1000]'
               });
	           //点击添加按钮操作
			   $('#save').click(function(){
                  $('#SysMenu_modifyItem').submit();
	            });
			    //添加行函数判断 孙灵军 2011-11-16
			   $('#add').click(function(){
				  <s:if test="po.intLevel==0">
                  addRow();
				  <s:else>
				  alert('不能添加！');
				   </s:else>
				  </s:if>
	            });
			 
	            //表单验证及提交处理操作
	           $('#SysMenu_modifyItem').form({
			        url:'<%=basePath%>SysMenu_modify.action?op=savejs',
			        onSubmit: function(){
			            //初始化验证控件
			            var name = $("input[id='name']");
			        	for(var i=0;i<name.length;i++){
			        	   $(name[i]).validatebox({required:'true',missingMessage:'必须输入操作名称',validType:'length[1,15]&specialChar'});
						 }	
						 
                        var simpleName = $("input[id='simpleName']");
			        	for(var i=0;i<simpleName.length;i++){
			        	   $(simpleName[i]).validatebox({required:'true',missingMessage:'必须输入操作简写',validType:'length[1,20]&specialChar'});
						 }
						 
			            var nseq = $("input[id='nseq']");
			        	for(var i=0;i<nseq.length;i++){
			        	   $(nseq[i]).validatebox({required:'true',missingMessage:'必须输入数字排序号',validType:'intNumber[0,9999]'});
						 }	
						
						//函数名称 
						var funname = $("input[id='funname']");
						for(var i=0;i<nseq.length;i++){
			        	   $(funname[i]).validatebox({validType:'length[1,25]&specialChar'});
						 }
						//按钮名称
						var idname = $("input[id='idname']");
						for(var i=0;i<nseq.length;i++){
			        	   $(idname[i]).validatebox({validType:'length[1,15]&specialChar'});
						 } 
						//按钮图标 
						var ico = $("input[id='ico']");
						for(var i=0;i<nseq.length;i++){
			        	   $(ico[i]).validatebox({validType:'length[1,25]&specialChar'});
						 }  
						 	
			            if($(this).form('validate')){
			                 $.util.showLoading();
			                 $('#operateWindow').window('close');
                            return true;
			             }else{
			                return false;
			             }
			        },			        
					success:function(data){
			            $.util.removeLoading();
			            try{
				            jsonReStr = jQuery.parseJSON(data);  //获取从服务器得到的数据反馈信息
				            if(jsonReStr.opState=="success"){    //操作成功处理
					            $.util.showTip({content:'数据修改成功！'});
								//在树上修改节点
					            var node = $('#<%=treeName%>').tree('getSelected');
								if (node){
									node.text = $('#vcName').val();
									node.id = $('#vcId').val();
									$('#<%=treeName%>').tree('update', node);
								}
								//更新查看界面
								//$("#<%=viewAreaName%>").load("<%=basePath%>SysMenu_look.action?chkSelf="+node.id+"&viewAreaName=<%=viewAreaName%>&treeName=<%=treeName%>");
								$("#menuManager").load("<%=basePath%>SysMenu_look.action?chkSelf="+node.id+"&viewAreaName=<%=viewAreaName%>&treeName=<%=treeName%>&tt=");
				            }else if(jsonReStr.opState=="failure"){  //操作失败处理
				                $.messager.alert('消息提示','操作处理失败！原因如下：<br><font color=red>'+jsonReStr.opInfo+'</font>','error');
				            }
			            }catch(e){
			               $.messager.alert('消息提示','出现系统错误!可能原因如下：<br><font color=red>'+this.url+'页面地址未找到！</font>','error');
			            }
			        }
				});
	            
           });
           
		var showIcons = function() {
			var dialog = parent.sy.modalDialog({
				title : '浏览小图标',
				url : '<%=path%>/extIcon/icons.jsp',
				buttons : [ {
					text : '确定',
					handler : function() {
						dialog.find('iframe').get(0).contentWindow.selectIcon(dialog, $('#vcIconCls'));
					}
				} ]
			});
		};
           
           //删除行
           function delRow(obj,vcId){
               if(vcId!=null){
                  if(obj.checked){
                      $('#delFlag'+vcId).val("1");
                  }else{    
                      $('#delFlag'+vcId).val("0");
                  }    
               }else{
                  $(obj).parent().parent().remove();
               }              
           }
           //添加行
           function addRow(){
              var row = '        <tr id="dataRow">'+
            '<td><INPUT type="text" id="nseq" name="opts.nseq" style="width:100%" value="0"/></td>'+
            '<td><INPUT type="text" id="name" name="opts.vcName"  style="width:100%"/></td>'+
            '<td><INPUT type="text" id="simpleName" name="opts.vcSimpleName"  style="width:100%"/></td>'+
            '<td><INPUT type="text" id="funname" name="opts.vcFunname"  style="width:100%"/></td>'+
            '<td><INPUT type="text" id="idname" name="opts.vcIdname"  style="width:100%"/></td>'+
            '<td><INPUT type="text" id="ico" name="opts.vcIco"  style="width:100%"/></td>'+
            '<td align="center"><input type="checkbox" onclick="delRow(this)"/></td>'+
            '<INPUT type="hidden" id="vcid" name="opts.vcId"/>'+
            '<INPUT type="hidden" name="opts.vcMenuId" value="<s:property value="po.vcId"/>"/>'+
            '<INPUT type="hidden"  name="opts.vcDelFlag" value="0"/>'+
            '</tr>';
            $('#rowBody').append(row);
           }
//-->
</script>
  </head>
  
  <body>
    <s:form action="SysMenu_modifyItem" method="post">
    <s:hidden id="vcId"  name="po.vcId" label="系统编号(主键)"></s:hidden>
    <s:hidden id="intLevel"  name="po.intLevel" label="菜单的层次(1,2,3,4)"></s:hidden>
    <s:hidden id="vcLinkUrl"  name="po.vcLinkUrl" label="合并菜单的主界面链接路径"></s:hidden>
    <s:hidden id="vcDelFlag"  name="po.vcDelFlag" label="删除标记(0未删除 1已删除)"></s:hidden>
	<table align="center" width="100%"  class="tb_add_th">
	<tr><th>菜单名称:</th><td><s:textfield id="vcName"  name="po.vcName" label="菜单名称" style="width:200px"></s:textfield><font color="red">*</font></td></tr>
	<tr><th>菜单URL:</th><td><s:textfield id="vcUrl"  name="po.vcUrl" label="菜单URL" style="width:200px"></s:textfield></td></tr>
	<tr><th>所属菜单:</th><td><s:textfield id="vcParId"  name="po.vcParId" label="父菜单ID" style="width:200px"></s:textfield></td></tr>
	<tr><th align="left">菜单图标:</th><td><s:textfield id="vcIconCls" name="po.vcIconCls" readonly="readonly" style="width: 200px;" /><img class="<s:property value="po.vcIconCls"/>" style="width:15px;" title=" " />&nbsp;<img class="iconImg ext-icon-zoom" onclick="showIcons();" title="浏览图标" />&nbsp;<img class="iconImg ext-icon-cross" onclick="$('#iconCls').val('');$('#iconCls').attr('class','');" title="清空" /></td></tr>
	<tr><th>排序号:</th><td><s:textfield id="intSeq"  name="po.intSeq" label="排序号" style="width:200px"></s:textfield><font color="red">*</font></td></tr>
	<tr><th>是否为子系统:</th><td><s:select id="vcIsMerge"  name="po.vcIsMerge" label="是否为子系统" style="width:200px" emptyOption="false" list="#{0:'否', 1:'是'}" ></s:select></td></tr>
	<tr><th>参数配置:</th><td><s:textarea id="vcMemo"  name="po.vcMemo" label="菜单描述" style="width:99%;height:60px;"></s:textarea></td></tr>
</table>  
<s:if test="po.intLevel==0"> 
<table id="dataList"  class="tb_list_gen" style="width:600px;height:auto;" align="center">
   <caption>菜单功能</caption>
    <thead>
        <tr>
            <th width="40">排序</th>
            <th width="80" norowp="true">操作名称</th>
            <th width="80">操作简写</th>
            <th width="80">函数名称</th>
            <th width="80">按钮名称</th>
            <th width="80">图标</th>
            <th width="50">删除</th>
        </tr>
    </thead>
    <tbody id="rowBody">
    <s:iterator value="#request.searchResultData" status="operate">
        <tr>
            <td><INPUT type="text" id="nseq" name="opts.nseq" value="<s:property value="nseq"/>" style="width:100%"/></td>
            <td><INPUT type="text" id="name" name="opts.vcName"  value="<s:property value="vcName"/>" style="width:100%"/></td>
            <td><INPUT type="text" id="simpleName" name="opts.vcSimpleName" value="<s:property value="vcSimpleName"/>" style="width:100%"/></td>
            <td><INPUT type="text" id="funname" name="opts.vcFunname" value="<s:property value="vcFunname"/>" style="width:100%"/></td>
            <td><INPUT type="text" id="idname" name="opts.vcIdname"  value="<s:property value="vcIdname"/>" style="width:100%"/></td>
            <td><INPUT type="text" id="ico" name="opts.vcIco" value="<s:property value="vcIco"/>" style="width:100%"/></td>
            <td align="center"><input type="checkbox" onClick="delRow(this,'<s:property value="vcId"/>')"/></td>
            <INPUT type="hidden" id="vcid" name="opts.vcId" value="<s:property value="vcId"/>"/>
            <INPUT type="hidden" name="opts.vcMenuId" value="<s:property value="po.vcId"/>"/>
            <INPUT type="hidden" id="delFlag<s:property value="vcId"/>" name="opts.vcDelFlag" value="0"/>
        </tr>
   </s:iterator>    
    </tbody>
</table>   
</s:if>
   </s:form>
<!--<div align="right" style="padding-right:15px"><s:if test="po.intLevel==0"> <a id="add" href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-add">添加新操作</a></s:if><a id="save"  href="javascript:void(0)"class="easyui-linkbutton" iconCls="icon-save">保存</a></div>-->
  </body>
</html>

